package com.dongdongshop.config;

import com.aliyun.oss.ClientBuilderConfiguration;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.common.auth.CredentialsProvider;
import com.aliyun.oss.common.auth.DefaultCredentialProvider;
import com.aliyun.oss.common.comm.SignVersion;
import com.dongdongshop.constant.OssConstant;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
public class OssClientConfig {

    CredentialsProvider credentialsProvider = new DefaultCredentialProvider(OssConstant.ACCESSKEYID, OssConstant.ACCESSKEYSECRET);

    @Bean
     public OSS ossClient() {
        // 创建OSSClient实例。
        ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
        clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);
        OSS ossClient = OSSClientBuilder.create()
                .endpoint(OssConstant.ENDPOINT)
                .credentialsProvider(credentialsProvider)
                .clientConfiguration(clientBuilderConfiguration)
                .region(OssConstant.REGION)
                .build();
        return ossClient;
    }

}
